package com.hxf.dao.meal.impl; 

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hxf.common.PublicUtil;
import com.hxf.dao.BaseDaoImpl;
import com.hxf.dao.meal.MealBoxDao;
import com.hxf.dto.MealBoxDto;
import com.hxf.dto.ReturnData;
import com.hxf.exception.DaoLevelException;

@SuppressWarnings("unchecked")
@Repository("mealBoxDao")
public class MealBoxDaoImpl extends BaseDaoImpl implements MealBoxDao {

	@Override
	public ReturnData<MealBoxDto> findByMealBoxPage(MealBoxDto mealBoxDto, int targetPage, int pageSize) throws DaoLevelException {
		String sql = "";
		if (null != mealBoxDto) {
			if (PublicUtil.isNotNullAndEmpty(mealBoxDto.getName())) {
				sql = " and name like '%" + mealBoxDto.getName().trim() + "%'";
			}
			
			if (PublicUtil.isNotNull(mealBoxDto.getLowConsume())) {
				sql += " and lowConsume = " + mealBoxDto.getLowConsume();
			}
			
			if (PublicUtil.isNotNull(mealBoxDto.getPeopleNumber())) {
				sql  += " and peopleNumber = " + mealBoxDto.getPeopleNumber();
			}
			
			if (mealBoxDto.getRestaurantId() != null && mealBoxDto.getRestaurantId() != 0) {
				sql += " and restaurantId = " + mealBoxDto.getRestaurantId();
			}
		} 
		return super.findBy("from MealBoxDto where 1=1 " + sql, targetPage, pageSize);
	}

	@Override
	public List<MealBoxDto> findByMealBox(MealBoxDto mealBoxDto) throws DaoLevelException {
		String sql = "";
		if (mealBoxDto != null) {
			if (mealBoxDto.getRestaurantId() != null && mealBoxDto.getRestaurantId() != 0) {
				sql += " and restaurantId = " + mealBoxDto.getRestaurantId();
			}
		}
		return super.findBy("from MealBoxDto where 1=1" + sql); 
	}
}
